package com.songxh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.songxh.pojo.Clazz;
import com.songxh.pojo.Teacher;
import com.songxh.service.TeacherService;
import com.songxh.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author songxh
 * @create 2022-04-18-19:36
 */
@Api("Teacher控制器")
@RestController
@RequestMapping("/sms/teacherController")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;


    @ApiOperation("获取教师信息")
    @GetMapping("/getTeachers/{pageNo}/{pageSize}")
    public Result getTeachers(
            @ApiParam("页码")
            @PathVariable("pageNo")Integer pageNo,
            @ApiParam("每一页的页数")
            @PathVariable("pageSize")Integer pageSize,
            String clazzName,
            String name
    ){
        Page<Teacher> page=new Page<>(pageNo,pageSize);
        IPage<Teacher> pageRes =teacherService.getTeacherByOpr(page,name,clazzName);
        return Result.ok(pageRes);
    }


    @ApiOperation("添加或修改教师信息")
    @PostMapping("/saveOrUpdateTeacher")
    public Result saveOrUpdateTeacher(@ApiParam("该Teacher信息的JSON内容")@RequestBody Teacher teacher){
        //实现服务层的增加与修改操作
        //该方法在IService中已经存在，故而直接用即可
        teacherService.saveOrUpdate(teacher);
        return Result.ok();
    }


    @ApiOperation("删除教师信息")
    @DeleteMapping("/deleteTeacher")
    public Result deleteTeacher(@ApiParam("需要删除的Teacher的id值的JSON集合")@RequestBody List<Integer> ids){
        // .removeByIds(ids)该方法来自IService，由mybatisplus提供
        teacherService.removeByIds(ids);
        return Result.ok();
    }
}
